package com.ruoyi.weixin.juc;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.TimeUnit;

/**
 * @Description: TODO
 * @Author ONESTAR
 * @Date: 2021/12/21 9:31
 * @Version 1.0
 */
public class UnsafeList {

    public static void main(String[] args) throws InterruptedException {
        Data data = new Data();
        for (int j = 0; j < 2; ++j) {
            new Thread(() -> {
                for (int i = 0; i < 100; ++i) {
                    data.add();
                }
            }).start();
        }
        TimeUnit.SECONDS.sleep(1);
        data.print();
    }
}
class Data{
    ArrayList<Integer> arrayList = new ArrayList<>();
    public void add(){
        arrayList.add(new Random().nextInt(9));

    }
    public void print(){
        System.out.println(arrayList.size());
        for(int i=0;i<arrayList.size();++i){
            System.out.println("第"+i+"个元素："+arrayList.get(i));
        }
    }

}
